import java.util.Arrays;

public class MyStack {
    public int[] elem;
    public int usedSize;
    public MyStack(){
        elem=new int[10];
    }
    public int size(){
        return usedSize;
    }
    public void push(int data){
        if(isFull()){
            elem=kuoRong();
        }
        elem[usedSize]=data;
        usedSize++;
    }
    public int pop(){
        if(isEmpty()){
           throw new EmptyExpection("栈是空的 ");
        }
        int ret=elem[usedSize-1];
        usedSize--;
        return ret;
    }
    public int peek(){
        if(isEmpty()){
            throw new EmptyExpection("栈是空的 ");
        }
        int ret=elem[usedSize-1];
        return ret;
    }

    private boolean isEmpty(){
        if(usedSize==0){
            return true;
        }
        return false;
    }
    private boolean isFull(){
        if(usedSize==elem.length){
            return true;
        }
        return false;
    }
    private int[] kuoRong(){
        return Arrays.copyOf(elem,elem.length*2);  //以二倍扩容
    }

}
